package org.aeon.gamechatnest.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.aeon.gamechatnest.common.response.Result;
import org.aeon.gamechatnest.common.response.ResultBuild;
import org.aeon.gamechatnest.dto.PrivateLetterDto;
import org.aeon.gamechatnest.service.PrivateLetterService;
import org.aeon.gamechatnest.util.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 私信对话控制器
 *
 * @author : Qik 2024/5/13 14:15
 */
@Validated
@RestController
@RequestMapping("/private/letter")
@Tag(name = "PrivateLetterControllerApi", description = "私信对话控制器类API")
public class PrivateLetterController {
    @Autowired
    private PrivateLetterService privateLetterService;

    @Operation(
            summary = "创建一个私聊对话",
            description = "根据一个目标用户id创建其与当前登录用户间的对话，如果被隐藏则重新显示出来",
            parameters = {@Parameter(name = "toUserId", description = "目标用户id")}
    )
    @PostMapping
    public Result createPrivateLetter(Long toUserId) {
        boolean res = privateLetterService.create(toUserId);
        return ResultBuild.successIf(res).build();
    }

    @Operation(summary = "获取用户所有私信列表", description = "获取用户所有私信列表")
    @GetMapping
    public Result privateMessageList() {
        List<PrivateLetterDto> privateLetters =
                privateLetterService.getPrivateMessageUsers(SecurityUtil.getUserId());
        return ResultBuild.result().successful().data(privateLetters).build();
    }

    @Operation(
            summary = "隐藏一个私聊对话",
            description = "根据私聊对话id，对当前登录用户隐藏该对话",
            parameters = {@Parameter(name = "id", description = "私聊对话id")}
    )
    @DeleteMapping
    public Result hidePrivateLetter(Long id) {
        boolean res = privateLetterService.hide(id);
        return ResultBuild.successIf(res).build();
    }


//    @Operation(
//            summary = "清除一个私聊对话的聊天记录",
//            description = "根据私聊对话id，清除聊天记录",
//            parameters = {@Parameter(name = "id", description = "私聊对话id")}
//    )
//    @PostMapping("/clear")
//    public Result clearPrivateLetter(Long id) {
//        Long deletedCount = privateLetterService.clear(id);
//        return ResultBuild.result().data(deletedCount).build();
//    }
}
